﻿using System;
using System.Xml.Linq;
using System.ComponentModel;
using Microsoft.VisualStudio.XmlEditor;
using System.Collections.Generic;

namespace CodeCounsel.SharePoint.RibbonDesigner.Model
{
    public abstract class NamedDomainElement
        : DomainElement
    {
        [TypeConverter(typeof(RibbonIdConverter))]
        public RibbonId Id
        {
            get { return DataModel.GetAttributeValue<RibbonId>(Schema.Id); }
            set { DataModel.SetAttributeValue(Schema.Id, value); }
        }

        protected NamedDomainElement(XElement dataModel,
            DomainModelSource source)
            : base(dataModel, source)
        {
        }

        protected NamedDomainElement()
        {
        }

        protected NamedDomainElement(RibbonId id)
        {
            Id = id;
        }

        internal override bool IsExtensionForElement(CommandUIDefinition cued)
        {
            return base.IsExtensionForElement(cued) ||
                cued.Type == CommandUIExtensionType.Append &&
                cued.Location == Id;
        }
    }
}
